package arrays常用api;

import java.util.Arrays;
import java.util.Comparator;

public class 排序 {
    public static void main(String[] args) {
        int[] a={2,85,69,41,4};
        Arrays.sort(a);//默认升序
        System.out.println(Arrays.toString(a));
        Integer[] b={2,85,69,41,4};
        Arrays.sort(b, new Comparator<Integer>() {//必须是引用类型数据
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(Arrays.toString(b));
        Student[] s=new Student[3];
        s[0]=new Student("朱佳铖",18,80.5);
        s[1]=new Student("李佳辉",20,89.6);
        s[2]=new Student("启动器",3,105.8);
        System.out.println(Arrays.toString(s));//要重写toString方法
        Arrays.sort(s, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        });
        System.out.println(Arrays.toString(s));
    }
}
